package tcpTest;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {
	public static void main(String[] args) throws UnknownHostException, IOException {
		// 1.建立连接
		Socket client = new Socket("localhost", 8888);

		//2.取得IO
		InputStream bis = new FileInputStream(new File("aaa.jpg"));
		OutputStream bos = new BufferedOutputStream(client.getOutputStream());

		//3.写入数据
		byte[] buf = new byte[1024];
		int len = -1;
		while ((len = bis.read(buf)) != -1) {
			System.out.println(new String(buf));
			System.out.println("-------------------------------------------");
			bos.write(buf, 0, len);

		}

		bos.flush();
		
		
		bos.close();
		bis.close();
		// 关闭连接
		client.close();
	}
}
